/*
 *                        _oo0oo_
 *                       o8888888o
 *                       88" . "88
 *                       (| -_- |)
 *                       0\  =  /0
 *                     ___/`---'\___
 *                   .' \\|     |// '.
 *                  / \\|||  :  |||// \
 *                 / _||||| -:- |||||- \
 *                |   | \\\  - /// |   |
 *                | \_|  ''\---/''  |_/ |
 *                \  .-\__  '-'  ___/-. /
 *              ___'. .'  /--.--\  `. .'___
 *           ."" '<  `.___\_<|>_/___.' >' "".
 *          | | :  `- \`.;`\ _ /`;.`/ - ` : | |
 *          \  \ `_.   \_ __\ /__ _/   .-` /  /
 *      =====`-.____`.___ \_____/___.-`___.-'=====
 *                        `=---='
 * 
 * 
 *      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 * 
 *            佛祖保佑       永不宕机     永无BUG
 * 
 *        佛曰:  
 *                写字楼里写字间，写字间里程序员；  
 *                程序人员写程序，又拿程序换酒钱。  
 *                酒醒只在网上坐，酒醉还来网下眠；  
 *                酒醉酒醒日复日，网上网下年复年。  
 *                但愿老死电脑间，不愿鞠躬老板前；  
 *                奔驰宝马贵者趣，公交自行程序员。  
 *                别人笑我忒疯癫，我笑自己命太贱；  
 *                不见满街漂亮妹，哪个归得程序员？
 */



import { DeviceType } from './state'
import { Mutations } from './mutations'
import { AppMutationTypes } from './mutation-types'
import { ActionTypes } from './action-types'
type AugmentedActionContext = {
    commit<K extends keyof Mutations>(
        key: K,
        payload?: Parameters<Mutations[K]>[1],
    ): ReturnType<Mutations[K]>
}

export type Actions = {
    [ActionTypes.ACTION_TOGGLE_SIDEBAR](
        { commit }: AugmentedActionContext,
        withoutAnimation: boolean
    ): void
    [ActionTypes.ACTION_CLOSE_SIDEBAR](
        { commit }: AugmentedActionContext,
        withoutAnimation: boolean
    ): void
    [ActionTypes.ACTION_TOGGLE_DEVICE](
        { commit }: AugmentedActionContext,
        device: DeviceType
    ): void
}

export const actions: Actions = {
    [ActionTypes.ACTION_TOGGLE_SIDEBAR]({ commit }, withoutAnimation: boolean) {
        commit(AppMutationTypes.TOGGLE_SIDEBAR, withoutAnimation)
    },
    [ActionTypes.ACTION_CLOSE_SIDEBAR]({ commit }, withoutAnimation: boolean) {
        commit(AppMutationTypes.CLOSE_SIDEBAR, withoutAnimation)
    },
    [ActionTypes.ACTION_TOGGLE_DEVICE]({ commit }, device: DeviceType) {
        commit(AppMutationTypes.TOGGLE_DEVICE, device)
    }
}
